#!/bin/sh

# run from directory where this script is
cd `echo $0 | sed 's/\(.*\)\/.*/\1/'` # extract pathname
EXAMPLE_DIR=`pwd`

# check whether echo has the -e option
if test "`echo -e`" = "-e" ; then ECHO=echo ; else ECHO="echo -e" ; fi

$ECHO
$ECHO "$EXAMPLE_DIR : starting"
$ECHO
$ECHO "This example shows how to use cp.x to perform molecular dynamics"
$ECHO "simulation of SiO2."

# set the needed environment variables
. ../../../environment_variables

# required executables and pseudopotentials
BIN_LIST="cp.x"
PSEUDO_LIST="Si.pz-vbc.UPF O.pz-rrkjus.UPF"

$ECHO
$ECHO "  executables directory: $BIN_DIR"
$ECHO "  pseudo directory:      $PSEUDO_DIR"
$ECHO "  temporary directory:   $TMP_DIR"
$ECHO "  checking that needed directories and files exist...\c"

# check for directories
for DIR in "$BIN_DIR" "$PSEUDO_DIR" ; do
    if test ! -d $DIR ; then
        $ECHO
        $ECHO "ERROR: $DIR not existent or not a directory"
        $ECHO "Aborting"
        exit 1
    fi
done
for DIR in "$TMP_DIR" "$EXAMPLE_DIR/results" ; do
    if test ! -d $DIR ; then
        mkdir $DIR
    fi
done
cd $EXAMPLE_DIR/results

# check for executables
for FILE in $BIN_LIST ; do
    if test ! -x $BIN_DIR/$FILE ; then
        $ECHO
        $ECHO "ERROR: $BIN_DIR/$FILE not existent or not executable"
        $ECHO "Aborting"
        exit 1
    fi
done

# check for pseudopotentials
for FILE in $PSEUDO_LIST ; do
    if test ! -r $PSEUDO_DIR/$FILE ; then
       $ECHO
       $ECHO "Downloading $FILE to $PSEUDO_DIR...\c"
            $WGET $PSEUDO_DIR/$FILE \
                http://www.quantum-espresso.org/pseudo/1.3/UPF/$FILE 2> /dev/null
    fi
    if test $? != 0; then
        $ECHO
        $ECHO "ERROR: $PSEUDO_DIR/$FILE not existent or not readable"
        $ECHO "Aborting"
        exit 1
    fi
done
$ECHO " done"

# how to run executables
CP_COMMAND="$PARA_PREFIX $BIN_DIR/cp.x $PARA_POSTFIX"
$ECHO
$ECHO "  running cp.x as: $CP_COMMAND"
$ECHO

# clean TMP_DIR
$ECHO "  cleaning $TMP_DIR...\c"
rm -rf $TMP_DIR/*
$ECHO " done"

# molecular dynamics calculation
cat >  sio2.cp.start.xml << EOF
<?xml version="1.0" encoding="UTF-8"?>


<input calculation="cp">

	<cell type="qecell">
		<qecell ibrav="8" alat="9.28990">
			<real rank="1" n1="5">
				1.73206 1.09955 0.0 0.0 0.0
			</real>
		</qecell>
	</cell>

	<atomic_species ntyp="2">
		<specie name="O">
			<property name="mass">
				<real>16.00</real>
			</property>
			<property name="pseudofile">
				<string>O.pz-rrkjus.UPF</string>
			</property>
			<property name="ion_radius">
				<real>1.0</real>
			</property>
		</specie>
		<specie name="Si">
			<property name="mass">
				<real>28.00</real>
			</property>
			<property name="pseudofile">
				<string>Si.pz-vbc.UPF</string>
			</property>
			<property name="ion_radius">
				<real>1.0</real>
			</property>
		</specie>
	</atomic_species>

	<atomic_list units="bohr" nat="18" >
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.18829368  14.83237039   1.22882961
				</real>
			</position>
		</atom>	
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					7.83231469   6.78704039   1.22882961
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					2.07443467   5.99537992   4.73758250
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					6.72031366  14.04231898   4.73758250
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.96307134  11.26989826   7.87860582
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					8.60802134   3.22295920   7.87860582
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.96307134   4.81915267   9.14625133
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					8.60802134  12.86448267   9.14625133
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.18736469   1.25668055   5.58029607
				</real>
			</position>
		</atom>	
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					7.83324368   9.30201055   5.58029607
				</real>
			</position>
		</atom>	
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					2.07536366  10.09206195   2.07358613
				</real>
			</position>
		</atom>			
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					6.71938467   2.04673195   2.07358613
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					0.28891589   8.04533000   3.40456284
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					4.93386589   0.00000000   3.40456284
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					2.13389003  12.27717358  -0.04188031
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					6.77884003   4.23184358  -0.04188031
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					2.13389003   3.81348642   6.85202747
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					6.77884003  11.85881642   6.85202747
				</real>
			</position>
		</atom>					
	</atomic_list>		
	
	
	<field name="InputOutput">

		<parameter name="pseudo_dir">
			<string>
				$PSEUDO_DIR/
			</string>
		</parameter>
		
		<parameter name="outdir">
			<string>
				$TMP_DIR/
			</string>
		</parameter>
		
		<parameter name="restart_mode">
			<string>
				from_scratch
			</string>
		</parameter>
		
		<parameter name="iprint">
			<integer>
				20
			</integer>
		</parameter>
		
		<parameter name="startingwfc">
			<string>
				random
			</string>
		</parameter>
	
	</field>
	
	<field name="Numerics">

		<parameter name="ecutwfc">
			<real>
				20.0
			</real>
		</parameter>
		
		<parameter name="ecutrho">
			<real>
				150.0
			</real>
		</parameter>
	
	</field>
	
	<field name="Options">

		<parameter name="nbnd">
			<integer>
				48
			</integer>
		</parameter>
		
		<parameter name="qcutz">
			<real>
				150.0
			</real>
		</parameter>
		
		<parameter name="q2sigma">
			<real>
				2.0
			</real>
		</parameter>
		
		<parameter name="ecfixed">
			<real>
				16.0
			</real>
		</parameter>
	
	</field>
	
	<field name="Fields">

		<parameter name="nspin">
			<integer>
				1
			</integer>
		</parameter>
	
	</field>
	
	
	<field name="CP">
	
<!--nstep, dt e ion_dynamics esistono anche nel PW ma nn sapevo in che field metterli  -->
		<parameter name="nstep">
			<integer>
				20
			</integer>
		</parameter>
		
		<parameter name="dt">
			<real>
				5.0
			</real>
		</parameter>
		
		<parameter name="ion_dynamics">
			<string>
				none
			</string>
		</parameter>
<!-- Da qui in poi esistono solo in CP-->
		<parameter name="isave">
			<integer>
				20
			</integer>
		</parameter>
		
		<parameter name="nr1b">
			<integer>
				16
			</integer>
		</parameter>
		
		<parameter name="nr2b">
			<integer>
				16
			</integer>
		</parameter>
		
		<parameter name="nr3b">
			<integer>
				16
			</integer>
		</parameter>
		
		<parameter name="electron_dynamics">
			<string>
				damp
			</string>
		</parameter>
		
		<parameter name="electron_damping">
			<real>
				0.2
			</real>
		</parameter>
		
		<parameter name="emass">
			<real>
				700.0
			</real>
		</parameter>
		
		<parameter name="emass_cutoff">
			<real>
				3.0
			</real>
		</parameter>
		
		<parameter name="ndr">
			<integer>
				90
			</integer>
		</parameter>
		
		<parameter name="ndw">
			<integer>
				91
			</integer>
		</parameter>
		
		<parameter name="ampre">
			<real>
				0.01
			</real>
		</parameter>
			
	</field>
	
</input>
EOF
$ECHO "  running the calculation with fixed ions...\c"
$CP_COMMAND < sio2.cp.start.xml > sio2.cp.start.out
check_failure $?
$ECHO " done"

# molecular dynamics calculation
cat > sio2.cp.restart.xml << EOF
<?xml version="1.0" encoding="UTF-8"?>


<input calculation="cp">

	<cell type="qecell">
		<qecell ibrav="8" alat="9.28990">
			<real rank="1" n1="5">
				1.73206 1.09955 0.0 0.0 0.0
			</real>
		</qecell>
	</cell>

	<atomic_species ntyp="2">
		<specie name="O">
			<property name="mass">
				<real>16.00</real>
			</property>
			<property name="pseudofile">
				<string>O.pz-rrkjus.UPF</string>
			</property>
			<property name="ion_radius">
				<real>1.0</real>
			</property>
		</specie>
		<specie name="Si">
			<property name="mass">
				<real>28.00</real>
			</property>
			<property name="pseudofile">
				<string>Si.pz-vbc.UPF</string>
			</property>
			<property name="ion_radius">
				<real>1.0</real>
			</property>
		</specie>
	</atomic_species>

	<atomic_list units="bohr" nat="18" >
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.18829368  14.83237039   1.22882961
				</real>
			</position>
		</atom>	
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					7.83231469   6.78704039   1.22882961
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					2.07443467   5.99537992   4.73758250
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					6.72031366  14.04231898   4.73758250
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.96307134  11.26989826   7.87860582
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					8.60802134   3.22295920   7.87860582
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.96307134   4.81915267   9.14625133
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					8.60802134  12.86448267   9.14625133
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.18736469   1.25668055   5.58029607
				</real>
			</position>
		</atom>	
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					7.83324368   9.30201055   5.58029607
				</real>
			</position>
		</atom>	
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					2.07536366  10.09206195   2.07358613
				</real>
			</position>
		</atom>			
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					6.71938467   2.04673195   2.07358613
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					0.28891589   8.04533000   3.40456284
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					4.93386589   0.00000000   3.40456284
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					2.13389003  12.27717358  -0.04188031
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					6.77884003   4.23184358  -0.04188031
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					2.13389003   3.81348642   6.85202747
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					6.77884003  11.85881642   6.85202747
				</real>
			</position>
		</atom>					
	</atomic_list>		
	
	
	<field name="InputOutput">

		<parameter name="pseudo_dir">
			<string>
				$PSEUDO_DIR/
			</string>
		</parameter>
		
		<parameter name="outdir">
			<string>
				$TMP_DIR/
			</string>
		</parameter>
		
		<parameter name="restart_mode">
			<string>
				reset_counters
			</string>
		</parameter>
		
		<parameter name="iprint">
			<integer>
				50
			</integer>
		</parameter>
	
	</field>
	
	<field name="Numerics">

		<parameter name="ecutwfc">
			<real>
				20.0
			</real>
		</parameter>
		
		<parameter name="ecutrho">
			<real>
				150.0
			</real>
		</parameter>
	
	</field>
	
	<field name="Options">

		<parameter name="nbnd">
			<integer>
				48
			</integer>
		</parameter>
		
		<parameter name="qcutz">
			<real>
				150.0
			</real>
		</parameter>
		
		<parameter name="q2sigma">
			<real>
				2.0
			</real>
		</parameter>
		
		<parameter name="ecfixed">
			<real>
				16.0
			</real>
		</parameter>
	
	</field>
	
	<field name="Fields">

		<parameter name="nspin">
			<integer>
				1
			</integer>
		</parameter>
	
	</field>
	
	
	<field name="CP">
	
<!--nstep, dt e ion_dynamics esistono anche nel PW ma nn sapevo in che field metterli  -->
		<parameter name="nstep">
			<integer>
				50
			</integer>
		</parameter>
		
		<parameter name="dt">
			<real>
				15.0
			</real>
		</parameter>
		
		<parameter name="ion_dynamics">
			<string>
				none
			</string>
		</parameter>
<!-- Da qui in poi esistono solo in CP-->
		<parameter name="isave">
			<integer>
				50
			</integer>
		</parameter>
		
		<parameter name="nr1b">
			<integer>
				16
			</integer>
		</parameter>
		
		<parameter name="nr2b">
			<integer>
				16
			</integer>
		</parameter>
		
		<parameter name="nr3b">
			<integer>
				16
			</integer>
		</parameter>
		
		<parameter name="electron_dynamics">
			<string>
				damp
			</string>
		</parameter>
		
		<parameter name="electron_damping">
			<real>
				0.2
			</real>
		</parameter>
		
		<parameter name="emass">
			<real>
				700.0
			</real>
		</parameter>
		
		<parameter name="emass_cutoff">
			<real>
				3.0
			</real>
		</parameter>
		
		<parameter name="ndr">
			<integer>
				91
			</integer>
		</parameter>
		
		<parameter name="ndw">
			<integer>
				92
			</integer>
		</parameter>
			
	</field>
	
</input>
EOF
$ECHO "  running the calculation with fixed ions, restart...\c"
$CP_COMMAND < sio2.cp.restart.xml > sio2.cp.restart.out
check_failure $?
$ECHO " done"

# molecular dynamics calculation
cat > sio2.vc-cp.xml << EOF
<?xml version="1.0" encoding="UTF-8"?>


<input calculation="vc-cp">

	<cell type="qecell">
		<qecell ibrav="8" alat="9.28990">
			<real rank="1" n1="5">
				1.73206 1.09955 0.0 0.0 0.0
			</real>
		</qecell>
	</cell>

	<atomic_species ntyp="2">
		<specie name="O">
			<property name="mass">
				<real>16.00</real>
			</property>
			<property name="pseudofile">
				<string>O.pz-rrkjus.UPF</string>
			</property>
			<property name="ion_radius">
				<real>1.0</real>
			</property>
		</specie>
		<specie name="Si">
			<property name="mass">
				<real>28.00</real>
			</property>
			<property name="pseudofile">
				<string>Si.pz-vbc.UPF</string>
			</property>
			<property name="ion_radius">
				<real>1.0</real>
			</property>
		</specie>
	</atomic_species>

	<atomic_list units="bohr" nat="18" >
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.18829368  14.83237039   1.22882961
				</real>
			</position>
		</atom>	
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					7.83231469   6.78704039   1.22882961
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					2.07443467   5.99537992   4.73758250
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					6.72031366  14.04231898   4.73758250
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.96307134  11.26989826   7.87860582
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					8.60802134   3.22295920   7.87860582
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.96307134   4.81915267   9.14625133
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					8.60802134  12.86448267   9.14625133
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.18736469   1.25668055   5.58029607
				</real>
			</position>
		</atom>	
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					7.83324368   9.30201055   5.58029607
				</real>
			</position>
		</atom>	
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					2.07536366  10.09206195   2.07358613
				</real>
			</position>
		</atom>			
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					6.71938467   2.04673195   2.07358613
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					0.28891589   8.04533000   3.40456284
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					4.93386589   0.00000000   3.40456284
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					2.13389003  12.27717358  -0.04188031
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					6.77884003   4.23184358  -0.04188031
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					2.13389003   3.81348642   6.85202747
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					6.77884003  11.85881642   6.85202747
				</real>
			</position>
		</atom>					
	</atomic_list>		
	
	
	<field name="InputOutput">

		<parameter name="pseudo_dir">
			<string>
				$PSEUDO_DIR/
			</string>
		</parameter>
		
		<parameter name="outdir">
			<string>
				$TMP_DIR/
			</string>
		</parameter>
		
		<parameter name="restart_mode">
			<string>
				reset_counters
			</string>
		</parameter>
		
		<parameter name="iprint">
			<integer>
				10
			</integer>
		</parameter>
		
	</field>
	
	<field name="Numerics">

		<parameter name="ecutwfc">
			<real>
				20.0
			</real>
		</parameter>
		
		<parameter name="ecutrho">
			<real>
				150.0
			</real>
		</parameter>
	
	</field>
	
	<field name="Options">

		<parameter name="nbnd">
			<integer>
				48
			</integer>
		</parameter>
		
		<parameter name="qcutz">
			<real>
				150.0
			</real>
		</parameter>
		
		<parameter name="q2sigma">
			<real>
				2.0
			</real>
		</parameter>
		
		<parameter name="ecfixed">
			<real>
				16.0
			</real>
		</parameter>
	
	</field>
	
	<field name="Fields">

		<parameter name="nspin">
			<integer>
				1
			</integer>
		</parameter>
	
	</field>
	
	<field name="VC-MD">

		<parameter name="nstep">
			<integer>
				10
			</integer>
		</parameter>
		
		<parameter name="cell_dynamics">
			<string>
				pr
			</string>
		</parameter>
		
		<parameter name="press">
			<real>
				1.0
			</real>
		</parameter>
	
	</field>
	
	
	<field name="CP">
	
<!--dt, ion_dynamics, ion_temperature e tempw esistono 
anche nel PW ma nn sapevo in che field metterli  -->
		
		<parameter name="dt">
			<real>
				12.0
			</real>
		</parameter>
		
		<parameter name="ion_dynamics">
			<string>
				verlet
			</string>
		</parameter>
		
		<parameter name="ion_temperature">
			<string>
				nose
			</string>
		</parameter>
		
		<parameter name="tempw">
			<real>
				300.0
			</real>
		</parameter>
<!-- Da qui in poi esistono solo in CP-->
		<parameter name="isave">
			<integer>
				10
			</integer>
		</parameter>
		
		<parameter name="nr1b">
			<integer>
				16
			</integer>
		</parameter>
		
		<parameter name="nr2b">
			<integer>
				16
			</integer>
		</parameter>
		
		<parameter name="nr3b">
			<integer>
				16
			</integer>
		</parameter>
		
		<parameter name="electron_dynamics">
			<string>
				verlet
			</string>
		</parameter>
		
		<parameter name="emass">
			<real>
				700.0
			</real>
		</parameter>
		
		<parameter name="emass_cutoff">
			<real>
				3.0
			</real>
		</parameter>
		
		<parameter name="ndr">
			<integer>
				92
			</integer>
		</parameter>
		
		<parameter name="ndw">
			<integer>
				93
			</integer>
		</parameter>
		
		<parameter name="ortho_max">
			<integer>
				30
			</integer>
		</parameter>
		
		<parameter name="fnosep">
			<real rank="1" n1="4">
				6.6666
                                6.6666
                                6.6666
                                6.6666
			</real>
		</parameter>
		
		<parameter name="cell_temperature">
			<string>
				nose
			</string>
		</parameter>
		
		<parameter name="temph">
			<real>
				300.0
			</real>
		</parameter>
		
		<parameter name="fnoseh">
			<real>
				8.6071
			</real>
		</parameter>
		
	</field>
	
</input>
EOF
$ECHO "  running the variable-cell calculation...\c"
$CP_COMMAND < sio2.vc-cp.xml > sio2.vc-cp.out
check_failure $?
$ECHO " done"

# molecular dynamics calculation
cat > sio2.vc-cp.restart.xml << EOF
<?xml version="1.0" encoding="UTF-8"?>


<input calculation="vc-cp">

	<cell type="qecell">
		<qecell ibrav="8" alat="9.28990">
			<real rank="1" n1="5">
				1.73206 1.09955 0.0 0.0 0.0
			</real>
		</qecell>
	</cell>

	<atomic_species ntyp="2">
		<specie name="O">
			<property name="mass">
				<real>16.00</real>
			</property>
			<property name="pseudofile">
				<string>O.pz-rrkjus.UPF</string>
			</property>
			<property name="ion_radius">
				<real>1.0</real>
			</property>
		</specie>
		<specie name="Si">
			<property name="mass">
				<real>28.00</real>
			</property>
			<property name="pseudofile">
				<string>Si.pz-vbc.UPF</string>
			</property>
			<property name="ion_radius">
				<real>1.0</real>
			</property>
		</specie>
	</atomic_species>

	<atomic_list units="bohr" nat="18" >
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.18829368  14.83237039   1.22882961
				</real>
			</position>
		</atom>	
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					7.83231469   6.78704039   1.22882961
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					2.07443467   5.99537992   4.73758250
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					6.72031366  14.04231898   4.73758250
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.96307134  11.26989826   7.87860582
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					8.60802134   3.22295920   7.87860582
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.96307134   4.81915267   9.14625133
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					8.60802134  12.86448267   9.14625133
				</real>
			</position>
		</atom>		
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					3.18736469   1.25668055   5.58029607
				</real>
			</position>
		</atom>	
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					7.83324368   9.30201055   5.58029607
				</real>
			</position>
		</atom>	
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					2.07536366  10.09206195   2.07358613
				</real>
			</position>
		</atom>			
		<atom name="O">
			<position>
				<real rank="1" n1="3">
					6.71938467   2.04673195   2.07358613
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					0.28891589   8.04533000   3.40456284
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					4.93386589   0.00000000   3.40456284
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					2.13389003  12.27717358  -0.04188031
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					6.77884003   4.23184358  -0.04188031
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					2.13389003   3.81348642   6.85202747
				</real>
			</position>
		</atom>			
		<atom name="Si">
			<position>
				<real rank="1" n1="3">
					6.77884003  11.85881642   6.85202747
				</real>
			</position>
		</atom>					
	</atomic_list>		
	
	
	<field name="InputOutput">

		<parameter name="pseudo_dir">
			<string>
				$PSEUDO_DIR/
			</string>
		</parameter>
		
		<parameter name="outdir">
			<string>
				$TMP_DIR/
			</string>
		</parameter>
		
		<parameter name="restart_mode">
			<string>
				reset_counters
			</string>
		</parameter>
		
		<parameter name="iprint">
			<integer>
				10
			</integer>
		</parameter>
		
	</field>
	
	<field name="Numerics">

		<parameter name="ecutwfc">
			<real>
				20.0
			</real>
		</parameter>
		
		<parameter name="ecutrho">
			<real>
				150.0
			</real>
		</parameter>
	
	</field>
	
	<field name="Options">

		<parameter name="nbnd">
			<integer>
				48
			</integer>
		</parameter>
		
		<parameter name="qcutz">
			<real>
				150.0
			</real>
		</parameter>
		
		<parameter name="q2sigma">
			<real>
				2.0
			</real>
		</parameter>
		
		<parameter name="ecfixed">
			<real>
				16.0
			</real>
		</parameter>
	
	</field>
	
	<field name="Fields">

		<parameter name="nspin">
			<integer>
				1
			</integer>
		</parameter>
	
	</field>
	
	<field name="VC-MD">

		<parameter name="nstep">
			<integer>
				10
			</integer>
		</parameter>
		
		<parameter name="cell_dynamics">
			<string>
				pr
			</string>
		</parameter>
		
		<parameter name="press">
			<real>
				1.0
			</real>
		</parameter>
	
	</field>
	
	
	<field name="CP">
	
<!--dt, ion_dynamics, ion_temperature e tempw esistono 
anche nel PW ma nn sapevo in che field metterli  -->
		
		<parameter name="dt">
			<real>
				12.0
			</real>
		</parameter>
		
		<parameter name="ion_dynamics">
			<string>
				verlet
			</string>
		</parameter>
		
		<parameter name="ion_temperature">
			<string>
				nose
			</string>
		</parameter>
		
		<parameter name="tempw">
			<real>
				300.0
			</real>
		</parameter>
<!-- Da qui in poi esistono solo in CP-->
		<parameter name="isave">
			<integer>
				10
			</integer>
		</parameter>
		
		<parameter name="nr1b">
			<integer>
				16
			</integer>
		</parameter>
		
		<parameter name="nr2b">
			<integer>
				16
			</integer>
		</parameter>
		
		<parameter name="nr3b">
			<integer>
				16
			</integer>
		</parameter>
		
		<parameter name="electron_dynamics">
			<string>
				verlet
			</string>
		</parameter>
		
		<parameter name="emass">
			<real>
				700.0
			</real>
		</parameter>
		
		<parameter name="emass_cutoff">
			<real>
				3.0
			</real>
		</parameter>
		
		<parameter name="ndr">
			<integer>
				93
			</integer>
		</parameter>
		
		<parameter name="ndw">
			<integer>
				94
			</integer>
		</parameter>
		
		<parameter name="ortho_max">
			<integer>
				30
			</integer>
		</parameter>
		
		<parameter name="fnosep">
			<real rank="1" n1="4">
				6.6666
                                6.6666
                                6.6666
                                6.6666
			</real>
		</parameter>
		
		<parameter name="cell_temperature">
			<string>
				nose
			</string>
		</parameter>
		
		<parameter name="temph">
			<real>
				300.0
			</real>
		</parameter>
		
		<parameter name="fnoseh">
			<real>
				8.6071
			</real>
		</parameter>
		
	</field>
	
</input>


EOF

$ECHO "  running the variable-cell calculation, restart...\c"
$CP_COMMAND < sio2.vc-cp.restart.xml >  sio2.vc-cp.restart.out
check_failure $?
$ECHO " done"

$ECHO
$ECHO "$EXAMPLE_DIR : done"
